<template>
  <div class="set-wrapper">
    <div class="header">
      <div class="return" @click="returnMethod"></div>
      <span>滤芯寿命</span>
    </div>
    <!--总共3000小时-->
    <div class="cell-list" v-for="(item,index) in batteryList" :key="index">
      <div class="name">滤网{{ index + 1 }}</div>
      <div class="cell-content">
        <div class="progress">
          <div class="trail">
            <span :style="{ width:((item.value / 3600) / 30) + '%' }">
              <p>
                剩余{{ (item.value/3600).toFixed(2) }}h
              </p>
            </span>
          </div>
        </div>
        <div class="recove" @click="recove(item.type,index)">滤网复位</div>
        
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import { Loading,Toast} from 'vue-ydui/dist/lib.rem/dialog';
import myUrl  from 'common/js/api'

export default {
  data () {
    return {
     value:'',
     pw:0,
     batteryList:[],
    }
  },
  created(){
    Loading.open('很快加载好了');
    setTimeout(() => {
      Loading.close();
    }, 300);
  },
  computed: {
  },
  watch: {
  },
  mounted(){
    this.pw = 80;
    if(sessionStorage.getItem('screens')){
      this.batteryList = JSON.parse(sessionStorage.getItem('screens'));
      console.log(this.batteryList)
    }
  },
  methods:{
    returnMethod(){
      this.$router.back(-1);
    },
    recove(type,index){
      let data = {};
      data.deviceId = this.$route.query.deviceId;
      data.funcId = type;
      Loading.open('很快加载好了');
      this.$http.post(myUrl.sendFunc,data).then(res => {
        if(res.code === 200){
          Loading.close();  
          this.batteryList[index].value = 10800000;
          sessionStorage.setItem('screens',JSON.stringify(this.batteryList));
          Toast({
              mes: '恢复成功',
              timeout: 1500,
              icon: 'success'
          });
        }
      })
      .catch(error =>{
        Loading.close();  
      })
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
  @import "src/common/scss/variable.scss";
  @import "src/common/scss/mixins.scss";
  .set-wrapper{
    position: absolute;
    width: 100%;
    height: 100%;
    top:0;
    .header{
      height: 40px;
      font-size: 16px;
      line-height: 40px;
      text-align: center;
      position: relative;
      .return{
        position: absolute;
        left:0px;
        background: url('../../assets/arr-left.png') no-repeat center center;
        background-size: 8px 16px;
        width: 40px;
        height: 40px;
        display: block;
        top:0px;
      }
    }
    .cell-list{
      background: #ffffff;
      margin-bottom: 5px;
      padding: 20px 20px 50px 20px;
      .name{
        font-size: 14px;
      }
      .cell-content{
        width: 100%;
        position: relative;
        overflow: hidden;
        .progress{
          float: left;
          width:70%;
          padding-left: 30px;
          padding-top: 50px;
          position: relative;
          .trail{
            width: 100%;
            height: 10px;
            background: #e6e6e6;
            border-radius: 20px;
            position: relative;
            & span{
              position: absolute;
              height: 10px;
              left:0;
              top:0;
              background: #3fa9f5;
              border-radius: 20px;
              transition: width 500ms ease;
              & p{
                position: absolute;
                height: 50px;
                width: 100px;
                top:-40px;
                font-size:14px;
                color: #3fa9f5;
                background: url('../../assets/san.png') no-repeat left  top 20px;
                background-size: 15px 13px;
              }
            }
          }
        }
        .recove{
          width: 22%;
          font-size: 12px;
          height: 23px;
          line-height: 23px;
          background: #1fb1fb;
          text-align: center;
          color: #ffffff;
          float: right;
          margin-top: 43px;
          border-radius: 5px;
          &.none{
            background: #f5f5f5;
            color: #4d4d4d;
          }
        }
      }
    }
  }
  
</style>

